<?php

namespace App\Admin\Extensions\Export;

use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\WithMapping;
use App\Admin\Models\Orders;
class OrdersExporter extends ExcelExporter implements WithMapping
{
    protected $fileName = '正常订单记录.xlsx';

    protected $columns = [
        'order_sn'            => '订单号',
        'goods_id'            => '商品名称',
        'uid'                 => '购买用户',
        'agent'               => '代理商',
        'created_at'          => '下单时间',
        'ad_name'             => '开卡人',
        'ad_phone'            => '联系电话',
        'status'              => '订单状态',
        'source'              => '订单来源',
        'created_at'          => '创建时间',
        'active_time'         => '激活时间',
    ];

    public function map($order) : array
    {
        return [
            $order->order_sn,
            $order->goods_id_text,
            $order->uid_text,
            $order->agent_text,
//            data_get($order,'Users.agent'),
            $order->created_at,
//            data_get($order,'Users.goods_id'),
            $order->ad_name,
            $order->ad_phone,
            $order->status_text,
            $order->source_text,
            $order->created_at,
            $order->active_time,
        ];
    }
}